//
//  FWMeViewController.m
//  BirdLoveSheep
//
//  Created by wwj on 16/4/13.
//  Copyright © 2016年 wwj. All rights reserved.
//

#import "FWMeViewController.h"
#import "FWMeHeaderView.h"
#import "FWMeCenterView.h"
#import "FWMeFooterView.h"
#import "FWMeWebController.h"

@interface FWMeViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollerView;

@end

@implementation FWMeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    self.scrollerView.backgroundColor = kBgColor;
    
    [self addHeaderView];
    [self addCenterView];
    [self addFooterView];
    
}

- (void)addHeaderView{
    FWMeHeaderView *headerView = [FWMeHeaderView headerView];
    headerView.y = 10;
    [self.scrollerView addSubview:headerView];
}

- (void)addCenterView{
    FWMeCenterView *centerView = [FWMeCenterView meCenterView];
    centerView.y = CGRectGetMaxY(self.scrollerView.subviews.lastObject.frame) + 10;
    [self.scrollerView addSubview:centerView];
}

- (void)addFooterView{
    FWMeFooterView *footerView = [FWMeFooterView footerView];
    footerView.y = CGRectGetMaxY(self.scrollerView.subviews.lastObject.frame) + 10;
    __weak typeof(FWMeFooterView) *wFooterView = footerView;
    footerView.heightBlock = ^(CGFloat height){
        self.scrollerView.contentSize = CGSizeMake(0, CGRectGetMaxY(wFooterView.frame));
       
    };
    [self.scrollerView addSubview:footerView];
    
    footerView.block = ^(FWSquareModel *model){
    FWMeWebController *webVC = [[FWMeWebController alloc] init];
    if ([model.url hasPrefix:@"http"] || [model.url hasPrefix:@"https"]) {
        webVC.url = model.url;
        webVC.title = model.name;
        [self.navigationController pushViewController:webVC animated:YES];
    }};
}

@end
